package cn.laixueit;

import cn.laixueit.mapper.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class TestMyBatis {
    public static void main(String[] args) throws IOException {
        // 加载核心配置文件
        InputStream stream = Resources.getResourceAsStream("mybatis.xml");

        // 得到会话工厂
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(stream);
        // 打开一个会话

        SqlSession session = sqlSessionFactory.openSession(true);

//        List<Object> list = session.selectList("test.findall");

//        System.out.println(list);

//        Student one = session.selectOne("test.findbyid");

//        System.out.println(one);

//        Object o = session.selectOne("test.findbyid", 2);
//        System.out.println(o);


        StudentMapper mapper = session.getMapper(StudentMapper.class);
//        System.out.println(mapper.findall());
//        System.out.println(mapper.findbyid(2));

//        Student student = new Student();
//        student.setUsername("建国");
//        student.setAddress("武汉");
//        mapper.save(student);

        int i = mapper.delbyid(5);

        System.out.println(i);
    }
}
